Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionality for FB messenger API #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

added functionality for FB messenger API #48

wants to merge 3 commits into from

Conversation

Potrimpo
Copy link
Contributor

addition to public API for talking to Messenger.

I can rename to post(:msg, ...) to be the same as the existing post(:video, ...) if that's hugely preferable, but personally I think separating the namespace is cleaner

@mweibel
Copy link
Owner

mweibel commented Oct 20, 2017

Why did you chose to put post_message in graph.ex while usually the whole API functions are in facebook.ex with clear parameters to create the payload? I don't currently see a reason to add a specialised post method which just has a predefined URL and content type but the arguments are so generic..?

@Potrimpo
Copy link
Contributor Author

You need a specialised post function because the messenger API requires the application/json header to be set, and a new function is the only way to pass in those headers without changing the arity of an existing in-use function

If you're okay with changing the existing post function to allow for passing in headers then I'll do that. I'm just aiming for zero impact area to begin with.

@mweibel
Copy link
Owner

mweibel commented Oct 20, 2017

I see. I wonder if we couldn't just set that Content Type by default on the post function? The post video is already separate so that should be ok I assume?

@Potrimpo
Copy link
Contributor Author

We can do it if you're ok with changing all calls to post to add a [] to the argument list, but if you mean default as in without changing the calling code, then it's finicky.

If we add a parameter with a default value headers \\ [content_type: "application/JSON"] then the default post and the post video function end up with the same arity and the compiler complains.

It wants:

def post(path, payload, params, options, headers \\ default)
def post(path, payload, params, options, headers) do ... end
def post(:video, path, payload, params, options) do .. end

But the problem with that is you get the default for headers but the top bodyless clause arguments are out of sync with the arguments of post(:video, ...) which is pretty clunky

And if we set the headers inside the function body then we're locked in to always using JSON. The messenger API doesn't take anything else, but other endpoints might.

@mweibel
Copy link
Owner

mweibel commented Oct 23, 2017

Sorry for replying late.

We can do it if you're ok with changing all calls to post to add a [] to the argument list, but if you mean default as in without changing the calling code, then it's finicky.

Let's do that. 👍

@mweibel mweibel mentioned this pull request Oct 24, 2017
5 tasks
@tfinnell
Copy link
Collaborator

In #44 I brought up the idea of replacing the Graph module with HTTPoison. I've only experimented with this mildly, and was too fearful of breaking stuff, but, if implemented, it would let us pass headers directly to the http library in a consistent way that's already documented for us. We could also configure the default headers in the module that wraps HTTPoison.Base and override them where necessary.

I was procrastinating on making these changes until the open PR's were merged, but given this could potentially save some effort here, I will make something public sooner.

@mweibel
Copy link
Owner

mweibel commented Oct 28, 2017

@Potrimpo could you rebase your changes on master please?

@tfinnell tfinnell mentioned this pull request Nov 9, 2017
@mweibel
Copy link
Owner

mweibel commented Jul 3, 2018

ping?

@mweibel
Copy link
Owner

mweibel commented Oct 26, 2018

@Potrimpo could you please update your PR to the latest changes? Otherwise I'll have to close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants